#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 310, M = 8010;
int fa[N];
int ret = 0;
struct node
{
    int x, y, z;
}e[M];
int n, m;
int find(int x)
{
    return fa[x] == x ? x : fa[x] = find(fa[x]);
}
bool cmp(node& s1, node& s2)
{
    return s1.z < s2.z;
}
int kk()
{
    sort(e + 1, e + m + 1, cmp);
    for (int i = 1; i <= m; i++)
    {
        int x = e[i].x;
        int y = e[i].y;
        int z = e[i].z;
        int fx = find(x);
        int fy = find(y);
        if (fx != fy)
        {
            ret = max(ret, z);
            fa[fx] = fy;
        }
    }
    return ret;
}
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> e[i].x >> e[i].y >> e[i].z;
    }
    for (int i = 1; i <= n; i++)
    {
        fa[i] = i;
    }
    int ret = kk();
    cout << n - 1 << " " << ret << endl;
    return 0;
}